using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using OpenSocial.Net.People;

namespace OpenSocial.Net.Web.Sample.UserControls
{
	public partial class FriendListControl : System.Web.UI.UserControl
	{
		FriendList _flist = new FriendList();

		public FriendList FriendListObject
		{
			get { return _flist; }
			set { _flist = value; }
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			rptFriends.ItemDataBound += new RepeaterItemEventHandler(rptFriends_ItemDataBound);
		}

		void rptFriends_ItemDataBound(object sender, RepeaterItemEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
			{
				Friend friend = e.Item.DataItem as Friend;
				if (friend != null)
				{
					FriendControl cntrl = e.Item.FindControl("FriendControl1") as FriendControl;
					if (cntrl != null)
					{
						cntrl.FriendObject = friend;
					}
				}
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (_flist != null && _flist.Friends.Count > 0)
			{
				rptFriends.DataSource = _flist.Friends;
				rptFriends.DataBind();
			}
		}
	}
}